package com.seed.service.sysmanager;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.seed.commons.dbquery.PageModelForSQL;
import com.seed.commons.dbutil.DB;
import com.seed.commons.dbutil.DBBean;
import com.seed.commons.util.RandomUtil;
import com.seed.web.form.sysmanager.MenuModelForm;

@Service
public class MenuModelService implements IMenuModel{

	private Log log = LogFactory.getLog(getClass()) ;
	
	@Override
	public boolean saveMenuModel(MenuModelForm mm) {
		String sql = "INSERT INTO SEED_MENU_MODEL(MMId,MMName,MMUrl,MMDesc,Sort) VALUES(?,?,?,?,?)" ;
		Object[] val = new Object[]{RandomUtil.getRandomNum(5),mm.getMmName(),mm.getMmUrl(),mm.getMmDesc(),mm.getSort()} ;
		try {
			DB.insert(sql, val) ;
			return true ;
		} catch (Exception e) {
			log.info("数据插入出错：" + e.getMessage()) ;
			log.info("执行SQL：" + sql) ;
		}
		return false ;
		
	}

	@Override
	public void deleteMenuModel(String id) {
		
		
	}

	@Override
	public void updateMenuModel(MenuModelForm mm) {
		
		
	}

	@Override
	public DBBean queryMenuModelById(String id) {
		
		return null;
	}

	@Override
	public PageModelForSQL getScrollData(int currentPage, int lineSize) {
		
		return null;
	}
	
	@Override
	public List<DBBean> queryMenuModel() {
		
		String sql = "SELECT MMId,MMName,MMUrl,MMDesc,Sort,to_char(addDate,'yyyy-MM-dd') addDate FROM SEED_MENU_MODEL" ;
		
		try {
			return DB.query(sql, null) ;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
